package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.EstateAdviserService;
import com.yixun.qfbao.apidto.ChangeCPAdviserReqDto;
import com.yixun.qfbao.apidto.GetCPCountByAdviserReqDto;
import com.yixun.qfbao.apidto.GetCPCountByAdviserResDto;
import com.yixun.qfbao.apidto.base.CommonResDTO;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.vo.ChangeCPAdviserReqVo;
import com.yixun.qfbao.vo.GetCPCountByAdviserReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service("getCPCountByAdviserHander")
public class GetCPCountByAdviserHander extends CommonAbstractHander {
    private static Logger logger= LoggerFactory.getLogger(GetCPCountByAdviserHander.class);

    @Autowired
    EstateAdviserService estateAdviserService;

    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        GetCPCountByAdviserReqVo req = (GetCPCountByAdviserReqVo)reqDto;
        GetCPCountByAdviserReqDto reqDto1 = req.getParams();
        BaseResponseDTO<GetCPCountByAdviserResDto> res = new BaseResponseDTO<>();
        GetCPCountByAdviserResDto resDto = new GetCPCountByAdviserResDto();
        res.setResult(ResultEnum.FAIL.getNo());
        try {
            int count = 0;
            if(Objects.nonNull(reqDto1.getAdviserUuid())){
                count = estateAdviserService.getCPCountByAdviser(reqDto1);
            }
            resDto.setCount(count);
            resDto.setResult(ResultEnum.SUCCESS.getNo());
            res.setResult(ResultEnum.SUCCESS.getNo());
            res.setResData(resDto);
            return res;
        }catch (Exception e){
            logger.error("get cp count by adviser, adviserUuid {}, exception: {}", reqDto1.getAdviserUuid(), e);
            res.setResult(ResultEnum.FAIL.getNo());
            res.setErrorMsg("置业顾问删除失败!");
        }
        return res;
    }
}
